package com.atguigu.algorithm;

import java.util.Scanner;

public class RedAndBlack {
    public static int count=0;
    static byte[][] direct = {{-1, 0},{1, 0},{0,-1},{0,1}};
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while(scanner.hasNext()){
            int m=scanner.nextInt();
            int n=scanner.nextInt();
            int x=0;
            int y=0; //用x,y记录初始点的位置
            char[][] map=new char[m][n];
            for(int i=0;i<m;i++){
                String s=scanner.next();
                for(int j=0;j<n;j++){
                    map[i][j]=s.charAt(j);
                    if(map[i][j]=='@'){
                        x=i;
                        y=j;
                    }
                }
            }
            count=0;
            dfs(map,x,y,m,n);
            System.out.println(count);
        }
    }
    public static void dfs(char[][] map,int x,int y,int row,int col){
        if(x<0 || y<0 || x>=row || y>=col){
            return;
        }
        if(map[x][y]=='#'){
            return;
        }
        //黑砖，走过后就修改
        count++;
        map[x][y]='#';
        //遍历四个方向
        dfs(map,x+1,y,row,col);
        dfs(map,x-1,y,row,col);
        dfs(map,x,y-1,row,col);
        dfs(map,x,y+1,row,col);
    }
}
